// 将文base64转文件对象
export const base64ToFile = (base64, fileName = '') => {
    let arr = base64.split(',')
    let mime = arr[0].match(/:(.*?);/)[1]
    let bstr = atob(arr[1])
    let n = bstr.length
    let u8arr = new Uint8Array(n)
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n)
    }
    let blob = new Blob([u8arr], {
      type: mime
    })
    blob.lastModifiedDate = new Date()
    blob.name = fileName
    // console.log('functionbase64ToFile -> blob', blob) // file
    return blob
  }
   
  // 文件下载
  export const fileLocalDownLoad = (blob, fileName) => {
    let downloadElement = document.createElement('a')
    let href = window.URL.createObjectURL(blob)
    downloadElement.href = href
    downloadElement.download = decodeURIComponent(fileName)
    document.body.appendChild(downloadElement)
    downloadElement.click()
    document.body.removeChild(downloadElement)
    window.URL.revokeObjectURL(href)
  }
   
  // 节流
//   export function rafThrottle(fn) {
//     let locked = false;
//     return function (...args) {
//       if (locked) return;
//       locked = true;
//       window.requestAnimationFrame(_ => {
//         fn.apply(this, args);
//         locked = false;
//       });
//     };
//   }